<?php

namespace app\wechat\controller;

use app\admin\controller\Backend;
use app\wechat\model\WechatResponse;

/**
 * 菜单管理
 *
 * @icon fa fa-list-alt
 */
class Menu extends Backend
{

    public function _initialize()
    {
        parent::_initialize();
        $this->service = model('wechat/menu', 'service');
    }

    /**
     * 查看
     */
    public function index()
    {
        $menu = $this->service->menu();
        $responselist = array();
        $all = WechatResponse::all();
        foreach ($all as $k => $v)
        {
            $responselist[$v['eventkey']] = $v['title'];
        }
        $this->view->assign('responselist', $responselist);
        $this->view->assign('menu', $menu);
        return $this->view->fetch();
    }

    /**
     * 修改
     */
    public function edit()
    {
        $menu = $this->request->post("menu");
        $result = $this->service->edit($menu);
        if ($result === false){
            $this->code = -1;
            $this->msg = $this->service->getError();
            return;
        }
        $this->code = 1;
        return;
    }

    /**
     * 同步
     */
    public function sync()
    {
        $result = $this->service->sync();
        if ($result === false){
            $this->code = -1;
            $this->msg = $this->service->getError();
            return;
        }
        $this->code = 1;
        return;
    }

}
